﻿var sysInfoDialog, loading_dialog, expressLoginDialog, commonUploadDialog, expressRegDialog, regAgreementDialog;
var domain_source = 'http://css.gaitu.com';
if (document.domain.indexOf('gaitu.com') >= 0) {
    document.domain = 'gaitu.com';
    var reg_frm_url = 'http://www.gaitu.com/user/reg_unity.aspx';
    var login_frm_url = '';
    var upload_frm_url = 'http://service.gaitu.com/photo/unityphotointerface.aspx';
    var reg_agreement_frm_url = 'http://www.gaitu.com/user/reg_agreement.html';
} else if (document.domain.indexOf('gaitu.cn') >= 0) {
    document.domain = 'gaitu.cn';
    var reg_frm_url = 'http://mp.gaitu.cn/user/reg_unity.aspx';
    var login_frm_url = '';
    var upload_frm_url = 'http://service.gaitu.cn/photo/unityphotointerface.aspx';
    var reg_agreement_frm_url = 'http://mp.gaitu.cn/user/reg_agreement.html';
} else if (document.domain.indexOf('gaitu.eric') >= 0) {
    //document.domain = 'gaitu.eric';
    var reg_frm_url = 'http://mp.gaitu.eric/user/reg_unity.aspx';
    var login_frm_url = '';
    var upload_frm_url = 'http://service.gaitu.cn/photo/unityphotointerface.aspx';
    var reg_agreement_frm_url = 'http://mp.gaitu.eric/user/reg_agreement.html';
} else {
    document.domain = '61.136.198.221';
    var reg_frm_url = 'http://61.136.198.221/user/reg_unity.aspx';
    var login_frm_url = '';
    var upload_frm_url = 'http://service.gaitu.com/photo/unityphotointerface.aspx';
    var reg_agreement_frm_url = 'http://61.136.198.221/user/reg_agreement.html';
}
jQuery.cookie = function (name, value, options) {
    if (typeof value != 'undefined') {
        options = options || {};
        if (value === null) {
            value = '';
            options = $.extend({}, options);
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString();
        }
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else {
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};
function trim(findstr) {
    var myfind = findstr;
    for (var i = 0; i < findstr.length; i++) {
        var myfind = myfind.replace(" ", "");
    }
    return myfind;
}
function random_char(l) {
    var x = "0123456789qwertyuioplkjhgfdsazxcvbnm";
    var tmp = "";
    for (var i = 0; i < l; i++) {
        tmp += x.charAt(Math.ceil(Math.random() * 100000000) % x.length);
    }
    return tmp;
}

function showLoad(str) {
    if (typeof (str) == "undefined" || str == '') str = "数据加载中，请稍后...";
    var dialog_id = 'loadingDialog' + random_char(5);
    var d = document.createElement("div");
    d.id = dialog_id;
    d.className = "dialog_ctn";
    document.body.appendChild(d);
    document.getElementById(dialog_id).innerHTML = '<div class="loading_ctn"><img src="' + domain_source + '/images/loading_b.gif" />' + str + '</div>';
    var p = {
        content_id: dialog_id,
        title: '提示',
        width: 500,
        height: 120,
        draggable: true,
        closable: false
    };
    loading_dialog = new YY_dialog(p);
    loading_dialog.show_dialog();
}

function showInfo(infostr, nexturl) {
    if (document.getElementById('sysInfoDialog') == null) {
        var d = document.createElement("div");
        d.id = "sysInfoDialog";
        d.title = "提示";
        document.body.appendChild(d);
    }
    document.getElementById('sysInfoDialog').innerHTML = infostr;
    var p = {
        content_id: "sysInfoDialog",
        title: '提示',
        width: 500,
        height: 100
    };
    if (typeof nexturl != 'undefined' && nexturl != '') {
        p.buttons = {
            button1: { name: '确定', action: function () { sysInfoDialog.close_dialog(); window.location.href = nexturl; } }
        };
        p.height = 100;
    }
    sysInfoDialog = new YY_dialog(p);
    sysInfoDialog.show_dialog();
}
function show_agreement() {
    if (typeof expressRegDialog != 'undefined') expressRegDialog.close_dialog();
    if (document.getElementById('regAgreementDialog') == null) {
        var d = document.createElement("div");
        d.id = "regAgreementDialog";
        d.title = "改图网服务协议";
        document.body.appendChild(d);
    }
    document.getElementById('regAgreementDialog').innerHTML = '<iframe src="' + reg_agreement_frm_url + '" width="500" height=220" scrolling="no" allowtransparency="true" frameborder="0" id="reg_agreement_frm" name="reg_agreement_frm"></iframe>';
    var p = {
        content_id: "regAgreementDialog",
        title: '改图网服务协议',
        width: 510,
        height: 300,
        buttons: {
            button1: { name: '返回', action: function () { regAgreementDialog.close_dialog(); if (typeof expressRegDialog != 'undefined') expressRegDialog.show_dialog(); } }
        }
    };
    regAgreementDialog = new YY_dialog(p);
    regAgreementDialog.show_dialog();
}
function express_reg(callback) {
    if (document.getElementById('expressRegDialog') == null) {
        var d = document.createElement("div");
        d.id = "expressRegDialog";
        d.title = "快速注册改图网会员";
        document.body.appendChild(d);
    }
    var url = reg_frm_url;
    if (typeof callback != 'undefined') {
        url += '?callback=' + callback;
    }
    document.getElementById('expressRegDialog').innerHTML = '<iframe src="' + url + '" width="500" height=250" scrolling="no" allowtransparency="true" frameborder="0" id="common_reg_frm" name="common_reg_frm"></iframe>';
    var p = {
        content_id: "expressRegDialog",
        title: '注册改图网会员',
        width: 510,
        height: 300
    };
    expressRegDialog = new YY_dialog(p);
    expressRegDialog.show_dialog();
}

function induce_action_common(obj, output_str, type, reply_obj, callback) {
    if (typeof reply_obj != 'object') reply_obj = obj.next('span');
    if (typeof type == 'undefined') type = 'error';
    var obj_id = obj.attr('id');
    reply_obj.html(output_str).attr('class', type);
    obj.removeClass('error pass warn verifying').addClass(type);

    if (typeof callback != 'function') { }
}

function chg_vali_img() {
    document.getElementById("vali_img").src = '/control/gif.aspx?time=' + Math.random();
}

function express_reg_submit() {
    $('#expressReg p input').addClass('d').attr('disabled', 'disabled');
    $('#expressReg p button').addClass('d').attr('disabled', 'disabled').html('注册中，请稍后');
    var post_data = '&', check_input = false;
    $('#expressReg p input').each(function () {
        check_input = express_reg_check($(this));
        if (!check_input) {
            $('#expressReg p input').removeClass('d').removeAttr('disabled');
            $('#expressReg p button').removeClass('d').removeAttr('disabled').html('同意以下协议，立即注册');
            return false;
        }
        var obj_id = $(this).attr('id');
        post_data += obj_id + $(this).val();
    });
    if (check_input) {
        var post_data = "email=" + trim($('#email').val()) + "&uname=" + trim($('#uid').val()) + "&pwd=" + $('#pwd').val() + "&code=" + $('#vali_code').val() + '&type=reg';
        $.ajax({
            url: '/ajaxpage/login.aspx?dotype=2',
            type: 'POST',
            data: post_data,
            dataType: 'html',
            timeout: 60000,
            error: function (html) {

            },
            success: function (html) {
                //                var json = eval('(' + json_text + ')');
                if (html == 2) {
                    $('#vali_code').select().attr('vali_result', 'wrong');
                    chg_vali_img();
                    induce_action_common($('#vali_code'), '验证码错误，请重新输入', 'error', $('#vali_code').siblings('span'));

                } else if (html.split("￥￥￥")[0] == 1) {
                    //                    if ($('#expressReg').attr('callback') != '') eval('parent.' + $('#expressReg').attr('callback') + '(\'' + json_text + '\');');
                    $("#newHeadHtml").html(html.split("￥￥￥")[1]);
                    parent.expressRegDialog.close_dialog();
                } else if (html == 5) {
                    $('#uid').select();
                    induce_action_common($('#uid'), '用户名输入不正确，请重新输入');
                } else if (html == 3) {
                    $('#email').select();
                    induce_action_common($('#email'), '邮箱输入不正确，请重新输入');
                } else if (html == 6) {
                    $('#uid').select();
                    induce_action_common($('#uid'), '该用户名已被注册，请更换');
                } else if (html == 4) {
                    $('#email').select();
                    induce_action_common($('#email'), '该邮箱已被注册，请更换');
                } else if (html == 7) {
                    $('#pwd').select();
                    induce_action_common($('#pwd'), '密码输入不正确，请重新输入');
                }
                else if (html == 0) {
                    $('#email').select();
                    $('#pwd').select();
                    induce_action_common($('#email'), '账号或密码错误');
                }
                $('#expressReg p input').removeClass('d').removeAttr('disabled');
                $('#expressReg p button').removeClass('d').removeAttr('disabled').html('同意以下协议，立即注册');
            }
        });
    }
}

function express_reg_check(obj) {
    if (typeof obj != 'object') return false;
    if (typeof type == 'undefined') type = null;
    var obj_id = obj.attr('id'), obj_val = obj.val();
    var result = true;
    if (obj_id == 'uid') {
        if (obj.attr('vali_result') === 'wrong') {
            result = false;
        } else {

            if (obj.val().length < 4 || obj.val().length > 12) {
                induce_action_common(obj, '用户名长度为4-12个字符');
                result = false;
            }
            else {

                if (obj.attr('vali_result') === 'ok') {
                    induce_action_common(obj, '&nbsp;', 'pass');
                } else {
                    induce_action_common(obj, '正在验证用户名', 'verifying');
                    $.post("/ajaxpage/login.aspx?dotype=2", { uname: obj_val, type: 'reg', check_obj: 'uname' }, function (data) {
                        if (data == 1) {
                            induce_action_common(obj, '&nbsp;', 'pass');
                            obj.attr('vali_result', 'ok');
                        } else if (data == 5) {
                            induce_action_common(obj, '用户名包含非法字符');
                            result = false;
                            obj.attr('vali_result', 'wrong');
                        }
                        else if (data == 6) {
                            induce_action_common(obj, '用户名已存在，请更改');
                            result = false;
                            obj.attr('vali_result', 'wrong');
                        }
                    }, "html");
                }
            }
        }
    }
    if (obj_id == 'email') {
        if (obj.attr('vali_result') === 'wrong') {
            result = false;
        } else {
            induce_action_common(obj, '正在验证邮箱', 'verifying');
            var emailfilter = /^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,3}|\d+)$/i;
            if (!emailfilter.test(obj_val) || (obj_val.toLowerCase()).indexOf("asdf") > 0 || (obj_val.toLowerCase()).indexOf("jkl") > 0) {
                induce_action_common(obj, '邮箱输入不正确');
                result = false;
            }
            else if (obj_val.length < 5 || obj_val.length > 50) {
                induce_action_common(obj, '邮箱长度为5-50个字符');
                result = false;
            }
            else {
                if (obj.attr('vali_result') === 'ok') {
                    induce_action_common(obj, '&nbsp;', 'pass');
                } else {
                    $.post("/ajaxpage/login.aspx?dotype=2", { email: obj_val, type: 'reg', check_obj: 'email' }, function (data) {
                        if (data == 1) {
                            induce_action_common(obj, '&nbsp;', 'pass');
                            obj.attr('vali_result', 'ok');
                        } else if (data == 3) {
                            induce_action_common(obj, '邮箱输入错误，请重新输入');
                            result = false;
                            obj.attr('vali_result', 'wrong');
                        } else if (data == 4) {
                            induce_action_common(obj, '该邮箱已被注册，请更改');
                            result = false;
                            obj.attr('vali_result', 'wrong');
                        }
                    }, "html");
                }
            }
        }
    }
    if (obj_id == 'pwd') {
        if (obj.val().length < 4 || obj.val().length > 12) {
            induce_action_common(obj, '密码长度为4-12字符');
            result = false;
        }
        else {
            induce_action_common(obj, '&nbsp;', 'pass');
        }
    }
    if (obj_id == 'pwd2') {

        if (obj.val().length < 4 || obj.val().length > 12) {
            induce_action_common(obj, '密码长度为4-12字符');
            result = false;
        }
        else if (obj.val() != $('#pwd').val()) {
            induce_action_common(obj, '两次输入的密码不同');
            result = false;
        }
        else {
            induce_action_common(obj, '&nbsp;', 'pass');
        }
    }
    if (obj_id == 'vali_code') {
        if (obj.attr('vali_result') === 'wrong') {
            result = false;
        } else {
            re3 = /^[0-9]{4}$/;
            if (!re3.test(obj.val())) {
                induce_action_common(obj, '验证码输入不正确', 'error', obj.siblings('span'));
                result = false;
            }
            else {
                induce_action_common(obj, '&nbsp;', 'pass', obj.siblings('span'));
            }
        }
    }
    return result;
}
function card_login(data) {
    if (typeof data == 'undefined') return false;
    if (typeof data == 'string') {
        data = eval('(' + data + ')');
        data = data.data;
    }
    login_title_str = '<li> <a href="http://www.gaitu.com/logout.aspx">退出</a></li><li onmouseover="$(\'#tixing\').show();" id="btn_tixing"><img height="18" width="60" src="/images/an.jpg"><p onmouseout="$(\'#tixing\').hide();" id="tixing" style="display: none;"><a href="' + data.renwu + '">会员任务</a><a href="' + data.news + '">新短信(' + data.newsnum + ')</a></p></li><li>您好,图客:  <a href="' + data.spaceurl + data.uid + '" id="myurl">' + data.uname + '</a> </li>';
    $('#login').html(login_title_str);
}

function show_upload_dialog(callback, otherparam) {
    if (document.getElementById('commonUploadDialog') == null) {
        var d = document.createElement("div");
        d.id = "commonUploadDialog";
        d.title = "上传图片";
        document.body.appendChild(d);
    }
    var url = upload_frm_url;
    if (typeof callback != 'undefined') {
        url += '?callback=' + callback + '&callurl=' + otherparam;
    }
    document.getElementById('commonUploadDialog').innerHTML = '<iframe src="' + url + '" width="500" height="395" scrolling="no" allowtransparency="true" frameborder="0" id="select_img_frm" name="select_img_frm"></iframe>';
    var p = {
        content_id: "commonUploadDialog",
        title: '选择图片',
        width: 510,
        height: 450
    };

    commonUploadDialog = new YY_dialog(p);
    commonUploadDialog.show_dialog();
}
function express_login(func, regFunc) {
    if (typeof func != 'function') {
        func = null;
    }
    if (typeof regFunc == 'undefined') {
        regFunc = '';
    }
    if (document.getElementById('expressLogin') == null) {
        var d = document.createElement("div");
        d.id = 'expressLogin';
        document.body.appendChild(d);
        document.getElementById('expressLogin').innerHTML = '<p><label>用户名</label><input type="text" /><span>用户名或Email</span></p><p><label>密<font style="visibility:hidden">xx</font>码</label><input type="password" /><span></span> <a href="http://www.gaitu.com/findpwd.html" target="_blank">忘记密码</a></p><!--p class="vali_code"><label>验证码</label><span>验证码为4个字符</span></p--><p><button>登录</button>还没有账号，赶快去<a href="http://www.gaitu.com/reg.html" target="_blank" >注册</a></p><div style=" height:24px; line-height:24px;margin:8px 0 0 20px;"><p>您也可以用合作网站账号登录改图网：</p><p style=" height:30px;"><a  style="float:left; margin-right:12px;background:url(/images/qq.png) no-repeat left center; width:85px;height:36px;" href="javascript:void(0);" onclick="openQQ();"></a><a style="float:left; margin-right:12px;background:url(/images/sina.png) no-repeat left center; width:85px;height:36px;" href="javascript:void(0);" onclick="openWeiBo();"></a></a><a style="float:left; margin-right:12px;background:url(/images/alipay.png) no-repeat left center; width:85px;height:36px;" href="javascript:void(0);" onclick="openAliPay();"></a></p></div>';
        var p = {
            content_id: "expressLogin",
            title: '请先登录',
            width: 355,
            height: 240
        };
        expressLoginDialog = new YY_dialog(p);
        $('#expressLogin p input').focus(function () { $(this).addClass('active'); }).blur(function () { $(this).removeClass('active'); express_login_check($(this)); }).hover(function () { $(this).addClass('o'); }, function () { $(this).removeClass('o'); }).keydown(function (event) {
            $(this).removeClass('error');
            var e = typeof window.event == 'undefined' ? event : window.event;
            if (e.keyCode == '13') {
                if ($(this).attr('type') == 'text') {
                    e.keyCode = '9';
                }
                else
                    $('#expressLogin p button').click();
            }
        });
        $('#expressLogin p button').click(function () { express_login_submit(func); });
    }
    expressLoginDialog.show_dialog();
}

function express_login_submit(logined_func) {
    var check_result_text, check_result_password, post_data = '&';
    $('#expressLogin p input').each(function () {
        eval('check_result_' + $(this).attr('type') + '=express_login_check($(this));');
        if ($(this).attr('type') == 'password') {
            post_data += 'password=' + $(this).val();
        } else
            post_data = 'username=' + $(this).val() + post_data;
    });

    if (check_result_text && check_result_password) {
        $('#expressLogin p input').addClass('d').attr('disabled', 'disabled');
        $('#expressLogin p button').addClass('d').attr('disabled', 'disabled').html('登录中');
        $.ajax({
            url: '/ajaxpage/logon.aspx?dotype=1',
            type: 'POST',
            data: post_data,
            dataType: 'html',
            timeout: 60000,
            error: function (html) {
                //alert('读取失败，请稍后重试！');
            },
            success: function (html) {
                if (html.split("￥￥￥")[0] == 1) {
                    $('#expressLogin p button').html('登录成功');
                    window.setTimeout("expressLoginDialog.close_dialog();", 1000);
                    //                    chg_login_state(json);
                    $("#newHeadHtml").html(html.split("￥￥￥")[1]);
                    if (typeof logined_func == 'function') logined_func();
                } else if (html == 0 || html == -3) {
                    $("#expressLogin p span").html('');
                    $("#expressLogin p:first-child span").html('账号或密码错误');
                    $("#expressLogin p input").addClass('error').removeClass('d').removeAttr('disabled').removeClass('pass');
                    $('#expressLogin p button').removeClass('d').removeAttr('disabled').html('登录');
                }
            }
        });
    }
}

function chg_login_state(json) {

    if (json.data.usertype == 0)
        login_title_str = '<li>您好,图客: <a class="uid" href="' + json.data.spaceurl + json.data.uid + '" id="myurl">' + json.data.uname + '</a></li>';
    else
        login_title_str = '<li>您好,改客: <a class="uid" href="' + json.data.spaceurl + json.data.uid + '" id="myurl">' + json.data.uname + '</a></li>';
    login_title_str += '<li><a class="blance" href="' + json.data.gaibiurl + '" id="amygaibi">' + json.data.gaibi + '枚改币</a></li>';
    if (json.data.usertype == 0)
        login_title_str += '<li><a class="recharge" href="' + json.data.chongzhi + '">[充值]</a></li>';
    else
        login_title_str += '<li><a class="recharge" href="' + json.data.tixian + '">[提现]</a></li>';
    login_title_str += '<li id="top_remind_ctn" class="rtl' + (json.data.tixin == 1 ? ' s' : '') + '"><a id="remind">提醒</a>';
    login_title_str += '<p style="display: none;" class="sub_menu" id="remind_sub">';
    login_title_str += '<a class="message" href="' + json.data.news + '">新短信(' + json.data.newsnum + ')</a>';
    login_title_str += '<a class="task" href="' + json.data.renwu + '">会员任务</a></p></li>';
    login_title_str += '<li><a class="exit" href="' + json.data.exit + '">退出</a></li>';
    login_title_str += '<li><a class="exchange" href="http://duihuan.gaitu.com/">兑换</a></li>';
    login_title_str += '<li><a class="wed" href="http://wed.gaitu.com/">影楼秀</a></li>';
    login_title_str += '<li><a class="member" href="http://i.gaitu.com/">会员</a></li>';
    login_title_str += '<li><a class="help" href="http://help.gaitu.com/">帮助</a></li>';
    $('#top_link_right').html(login_title_str);
    $('#mygaitu').html('<a rel="nofollow" href="' + json.data.spaceurl + json.data.uid + '">我的改图</a>');
    $('#top_link_right #top_remind_ctn').hover(function () { $('#remind_sub').fadeIn(200); }, function () { $('#remind_sub').fadeOut(200); });
    if ($('#login')) {
        //login_title_str = '<li> <a href="http://www.gaitu.com/logout.aspx">退出</a></li><li onmouseover="$(\'#tixing\').show();" id="btn_tixing"><img height="18" width="60" src="/images/an.jpg"><p onmouseout="$(\'#tixing\').hide();" id="tixing" style="display: none;"><a href="' + json.data.renwu + '">会员任务</a><a href="' + json.data.news + '">新短信(' + json.data.newsnum + ')</a></p></li><li>您好,图客:  <a href="' + json.data.spaceurl + json.data.uid + '" id="myurl">' + json.data.uname + '</a>  <a href="http://i.gaitu.com/mpPrint/Default.aspx?uid=' + json.data.uid + '" style="color:#FF9C00" >订单查询</a>&nbsp;</li>';        
        $('#login').html(login_title_str);
    }
    if ($('#logMid')) {
        login_title_str = '<div class="logined_after"><div class="myGT"><a href="' + json.data.spaceurl + json.data.uid + '" class="GTtitle clear-fix"><em>我的改图</em><b class=""></b></a><ul style="display: none;"><li><a style="color:#FF9C00" href="' + json.data.mporder + '">订单查询</a></li><li><a href="' + json.data.renwu + '">会员任务</a></li><li><a href="' + json.data.news + '">新短信(' + json.data.newsnum + ')</a></li></ul></div><span class="name">hi，<a href="' + json.data.spaceurl + json.data.uid + '">' + json.data.uname + '</a>！&nbsp;<a href="' + json.data.exit + '">退出</a></span></div> ';
        $('#logMid').html(login_title_str);
    }
    $('.uid_share').replaceWith('<a class="uid_share" target="_blank"  href="' + "http://i.gaitu.com/EmailShare.html?uid=" + json.data.uid + '">推荐给好友</a>')
    $('.emailtuijian').replaceWith('<a class="emailtuijian" target="_blank"  href="' + "http://i.gaitu.com/EmailShare.html?uid=" + json.data.uid + '">邮箱推荐</a>')
}

function express_login_check(obj) {
    var tip_obj = obj.parent('p').children('span');
    var uid_filter = /^([\u4E00-\uFA29]|[\uE7C7-\uE7F3]|[\w])*$/;
    obj.addClass('error').removeClass('pass');

    if (obj.val() == '') {
        tip_obj.html(obj.parent('p').children('label').html().replace('xx', '') + '不能为空');
        return false;
    }
    if (obj.attr('type') == 'password') {
        if (obj.val().length > 12 || obj.val().length < 1) {
            tip_obj.html('密码错误');
            return false;
        }
    } else {
        if (obj.val().length > 75) {
            tip_obj.html('账号长度超过限制');
            return false;
        }
    }

    obj.removeClass('error');
    obj.addClass('pass');
    return true;
}

var get_width = function (obj) {
    var total_width;
    if (typeof obj == 'object') {
        total_width = obj.offsetWidth;
    } else {
        total_width = document.documentElement.clientWidth + document.documentElement.scrollLeft + document.body.scrollLeft;
    }
    return (total_width);
};

var get_height = function (obj) {
    var total_height;
    if (typeof obj == 'object') {
        total_height = obj.offsetHeight;
    } else {
        total_height = document.documentElement.clientHeight + document.documentElement.scrollTop + document.body.scrollTop;
    }
    return (total_height);
};
function YY_dialog(params) {
    this.dialog_width = 400;
    this.dialog_height = 300;
    this.draggable = true;
    this.closable = true;
    this.content_id = null;
    this.focus_btn = '';
    this.package = true;
    this.restrict = true;
    this.force_center = false;
    this.dragger = null;
    this.pos_x = null;
    this.pos_y = null;

    this.config = function (params) {
        if (typeof (params) == "object") {
            if (typeof (params.content_id) != 'undefined' && params.content_id != '') {
                this.content_id = params.content_id;
                this.dialog_id = "YY_dialog_ctn_" + params.content_id;
                this.dialog_bg_id = "YY_dialog_bg_" + params.content_id;
            } else {
                random_content_id = random_char(5);
                this.content_id = random_content_id;
                this.dialog_id = "YY_dialog_ctn_" + random_content_id;
                this.dialog_bg_id = "YY_dialog_bg_" + random_content_id;
            }
            if (typeof (params.width) != 'undefined' && params.width != '') this.dialog_width = params.width;
            if (typeof (params.height) != 'undefined' && params.height != '') this.dialog_height = params.height;
            if (typeof (params.buttons) != 'undefined' && params.buttons != '') this.YY_dialog_buttons = params.buttons;
            if (typeof (params.draggable) == 'boolean') this.draggable = params.draggable;
            if (typeof (params.close) != 'undefined' && params.close != '') this.close = params.close;
            if (typeof (params.closable) == 'boolean') this.closable = params.closable;
            if (typeof (params.title) != 'undefined' && params.title != '') this.title = params.title;
            if (typeof (params.package) != 'undefined' && !params.package) this.package = false;
            if (typeof (params.dragger) != 'undefined' && params.dragger != null) this.dragger = params.dragger;
            if (typeof (params.pos_x) != 'undefined' && params.pos_x != null) this.pos_x = params.pos_x;
            if (typeof (params.pos_y) != 'undefined' && params.pos_y != null) this.pos_y = params.pos_y;
            if (typeof (params.restrict) != 'undefined' && !params.restrict) this.restrict = false;
            if (typeof (params.force_center) != 'undefined' && params.force_center) this.force_center = true;
        }
    };

    this.create_dialog = function () {
        var YY_dialog_layer = document.createElement("div");

        YY_dialog_layer.id = "YY_dialog_ctn_" + this.content_id;
        YY_dialog_layer.style.position = "absolute";

        YY_dialog_layer.style.width = this.dialog_width + "px";
        YY_dialog_layer.style.height = this.dialog_height + "px";
        YY_dialog_layer.style.zIndex = 102;
        YY_dialog_layer.style.display = 'none';
        if (this.pos_x != null) {
            YY_dialog_layer.style.top = this.pos_x;
            YY_dialog_layer.style.left = this.pos_y;
        } else {
            YY_dialog_layer.style.top = Math.floor((get_height() - this.dialog_height) / 2) < 5 ? 5 : Math.floor((get_height() - this.dialog_height) / 2) + 'px';
            YY_dialog_layer.style.left = Math.floor((get_width() - this.dialog_width) / 2) < 5 ? 5 : Math.floor((get_width() - this.dialog_width) / 2) + 'px';
        }
        if (this.force_center) YY_dialog_layer.setAttribute('YY_dialog_position', 'center');

        var YY_dialog_title_ctn_layer = document.createElement("div");

        YY_dialog_title_ctn_layer.id = "YY_dialog_title_ctn_" + this.content_id;
        YY_dialog_title_ctn_layer.style.width = this.dialog_width + "px";
        YY_dialog_title_ctn_layer.style.height = 27 + "px";
        YY_dialog_title_ctn_layer.style.background = "#F8F5DD";
        if (this.draggable) {
            YY_dialog_title_ctn_layer.style.cursor = "move";
            YY_dialog_title_ctn_layer.onmousedown = down;
        }
        YY_dialog_title_ctn_layer.dialog_id = this.content_id;
        YY_dialog_title_ctn_layer.onselectstart = new Function("return false");

        var YY_dialog_title_layer = document.createElement("div");
        YY_dialog_title_layer.id = "YY_dialog_title_" + this.content_id;
        if (typeof (this.title) != 'undefined' && this.title != '') YY_dialog_title_layer.innerHTML = this.title;
        YY_dialog_title_layer.style.lineHeight = 23 + "px";
        YY_dialog_title_layer.style.fontSize = 14 + "px";
        YY_dialog_title_layer.style.fontWeight = 700;
        YY_dialog_title_layer.style.color = "#333";
        YY_dialog_title_layer.style.paddingLeft = 10 + "px";
        YY_dialog_title_layer.style.styleFloat = "left";
        YY_dialog_title_layer.style.cssFloat = "left";
        YY_dialog_title_layer.onselectstart = new Function("return false");
        YY_dialog_title_layer.style.height = 27 + "px";

        var YY_dialog_close_layer = document.createElement("div");
        YY_dialog_close_layer.id = "YY_dialog_close_" + this.content_id;
        YY_dialog_close_layer.onclick = this.close_dialog;
        YY_dialog_close_layer.content_id = this.content_id;
        if (typeof (this.close) == 'function') YY_dialog_close_layer.close = this.close;
        YY_dialog_close_layer.onmouseover = new Function('this.style.backgroundPosition="-13px -24px"');
        YY_dialog_close_layer.onmouseout = new Function('this.style.backgroundPosition="-13px -24px"');
        YY_dialog_close_layer.style.width = 20 + "px";
        YY_dialog_close_layer.style.display = "inline";
        YY_dialog_close_layer.style.height = 20 + "px";
        YY_dialog_close_layer.style.background = 'url("' + domain_source + '/images/default_dialog_bg.gif")';
        YY_dialog_close_layer.style.styleFloat = "right";
        YY_dialog_close_layer.style.cssFloat = "right";
        YY_dialog_close_layer.style.margin = "1px 6px 0 0";
        YY_dialog_close_layer.style.cursor = "pointer";
        YY_dialog_close_layer.style.backgroundPosition = "-13px -24px";

        var YY_dialog_top_layer = document.createElement("div");
        YY_dialog_top_layer.id = "YY_dialog_top_" + this.content_id;
        YY_dialog_top_layer.style.height = 5 + "px";
        YY_dialog_top_layer.style.overflow = "hidden";

        var YY_dialog_top_left_layer = document.createElement("div");

        YY_dialog_top_left_layer.id = "YY_dialog_top_left_" + this.content_id;
        YY_dialog_top_left_layer.style.width = 5 + "px";
        YY_dialog_top_left_layer.style.height = 5 + "px";
        YY_dialog_top_left_layer.style.background ='url("' + domain_source + '/images/default_dialog_bg.gif")';
        YY_dialog_top_left_layer.style.styleFloat = "left";
        YY_dialog_top_left_layer.style.cssFloat = "left";
        YY_dialog_top_left_layer.style.backgroundPosition = "-22px 0";
        YY_dialog_top_left_layer.style.overflow = "hidden";

        var YY_dialog_top_center_layer = document.createElement("div");
        YY_dialog_top_center_layer.id = "YY_dialog_top_center_" + this.content_id;
        YY_dialog_top_center_layer.style.width = this.dialog_width - 10 + "px";
        YY_dialog_top_center_layer.style.height = 5 + "px";
        YY_dialog_top_center_layer.style.styleFloat = "left";
        YY_dialog_top_center_layer.style.cssFloat = "left";
        YY_dialog_top_center_layer.style.background = "#F8F5DD";
        YY_dialog_top_center_layer.style.overflow = "hidden";

        var YY_dialog_top_right_layer = document.createElement("div");

        YY_dialog_top_right_layer.id = "YY_dialog_top_right_" + this.content_id;
        YY_dialog_top_right_layer.style.width = 5 + "px";
        YY_dialog_top_right_layer.style.height = 5 + "px";
        YY_dialog_top_right_layer.style.background ='url("' + domain_source + '/images/default_dialog_bg.gif")';
        YY_dialog_top_right_layer.style.styleFloat = "left";
        YY_dialog_top_right_layer.style.cssFloat = "left";
        YY_dialog_top_right_layer.style.backgroundPosition = "-28px 0";
        YY_dialog_top_right_layer.style.overflow = "hidden";


        YY_dialog_top_layer.appendChild(YY_dialog_top_left_layer);
        YY_dialog_top_layer.appendChild(YY_dialog_top_center_layer);
        YY_dialog_top_layer.appendChild(YY_dialog_top_right_layer);

        if (this.closable) {
            YY_dialog_title_ctn_layer.appendChild(YY_dialog_close_layer);
        }
        YY_dialog_title_ctn_layer.appendChild(YY_dialog_title_layer);

        YY_dialog_layer.appendChild(YY_dialog_top_layer);
        YY_dialog_layer.appendChild(YY_dialog_title_ctn_layer);

        var YY_dialog_content_layer = document.createElement("div");

        YY_dialog_content_layer.id = "YY_dialog_content_" + this.content_id;
        YY_dialog_content_layer.style.background = "#fff";
        YY_dialog_content_layer.style.overflow = "auto";
        YY_dialog_content_layer.style.padding = 5 + "px";
        YY_dialog_content_layer.style.height = this.dialog_height - 80 + "px";
        if (typeof (params.buttons) == "object") {
            YY_dialog_content_layer.style.height = this.dialog_height - 80 + "px";
        } else {
            YY_dialog_content_layer.style.height = this.dialog_height - 48 + "px";
        }
        YY_dialog_layer.appendChild(YY_dialog_content_layer);
        if (typeof (params.buttons) == "object") {
            var YY_dialog_action_ctn_layer = document.createElement("div");
            YY_dialog_action_ctn_layer.id = "YY_dialog_action_ctn_" + this.content_id;
            YY_dialog_action_ctn_layer.style.background = "#fff";
            YY_dialog_action_ctn_layer.style.height = 33 + "px";
            YY_dialog_action_ctn_layer.style.margin = "0 auto";
            YY_dialog_action_ctn_layer.style.padding = "0 10px 0 0";

            for (s in params.buttons) {
                if (params.buttons[s].name != '' && params.buttons[s].action != null) {
                    var YY_dialog_btn_layer = document.createElement("div");

                    YY_dialog_btn_layer.id = "YY_dialog_button_" + this.content_id + '_' + s;
                    if (params.buttons[s].action == "close")
                        YY_dialog_btn_layer.onclick = this.close_dialog;
                    else
                        YY_dialog_btn_layer.onclick = params.buttons[s].action;
                    if (params.buttons[s].enter_key) {
                        this.focus_btn = "YY_dialog_button_" + this.content_id + '_' + s;
                    }

                    YY_dialog_btn_layer.style.background ='url("' + domain_source + '/images/default_dialog_bg.gif")';
                    YY_dialog_btn_layer.content_id = this.content_id;
                    YY_dialog_btn_layer.onmouseover = new Function('this.style.backgroundPosition="0px -64px"');
                    YY_dialog_btn_layer.onmouseout = new Function('this.style.backgroundPosition="0px -64px"');
                    YY_dialog_btn_layer.style.cursor = "pointer";
                    YY_dialog_btn_layer.style.backgroundPosition = "0px -64px";
                    YY_dialog_btn_layer.style.styleFloat = "right";
                    YY_dialog_btn_layer.style.cssFloat = "right";
                    YY_dialog_btn_layer.style.margin = "0 5px";

                    var YY_dialog_btn_left_layer = document.createElement("div");
                    YY_dialog_btn_left_layer.id = "YY_dialog_button_left_" + this.content_id + '_' + s;
                    YY_dialog_btn_left_layer.style.width = 5 + "px";
                    YY_dialog_btn_left_layer.style.height = 29 + "px";
                    YY_dialog_btn_left_layer.style.styleFloat = "left";
                    YY_dialog_btn_left_layer.style.cssFloat = "left";
                    YY_dialog_btn_left_layer.style.background ='url("' + domain_source + '/images/default_dialog_bg.gif")';
                    YY_dialog_btn_left_layer.style.backgroundPosition = "0px -24px";

                    var YY_dialog_btn_center_layer = document.createElement("button");
                    YY_dialog_btn_center_layer.id = "YY_dialog_button_center_" + this.content_id + '_' + s;
                    YY_dialog_btn_center_layer.innerHTML = params.buttons[s].name;
                    YY_dialog_btn_center_layer.style.height = 26 + "px";
                    YY_dialog_btn_center_layer.style.styleFloat = "left";
                    YY_dialog_btn_center_layer.style.cssFloat = "left";
                    YY_dialog_btn_center_layer.style.display = "block";

                    YY_dialog_btn_center_layer.style.fontSize = 12 + "px";
                    YY_dialog_btn_center_layer.style.fontWeight = 700;
                    YY_dialog_btn_center_layer.style.textAlign = "center";
                    YY_dialog_btn_center_layer.style.color = "#333";
                    YY_dialog_btn_center_layer.style.padding = "0 3px";
                    YY_dialog_btn_center_layer.style.border = "0";
                    YY_dialog_btn_center_layer.style.margin = "0";
                    YY_dialog_btn_center_layer.style.background ='url("' + domain_source + '/images/default_dialog_bg.gif")';
                    YY_dialog_btn_center_layer.style.backgroundPosition = "0px -64px";


                    var YY_dialog_btn_right_layer = document.createElement("div");
                    YY_dialog_btn_right_layer.id = "YY_dialog_button_right_" + this.content_id + '_' + s;
                    YY_dialog_btn_right_layer.style.width = 7 + "px";
                    YY_dialog_btn_right_layer.style.height = 29 + "px";
                    YY_dialog_btn_right_layer.style.styleFloat = "left";
                    YY_dialog_btn_right_layer.style.cssFloat = "left";
                    YY_dialog_btn_right_layer.style.background ='url("' + domain_source + '/images/default_dialog_bg.gif")';
                    YY_dialog_btn_right_layer.style.backgroundPosition = "-6px -24px";


                    YY_dialog_btn_layer.appendChild(YY_dialog_btn_left_layer);
                    YY_dialog_btn_layer.appendChild(YY_dialog_btn_center_layer);
                    YY_dialog_btn_layer.appendChild(YY_dialog_btn_right_layer);
                    YY_dialog_action_ctn_layer.appendChild(YY_dialog_btn_layer);
                }
            }
            YY_dialog_layer.appendChild(YY_dialog_action_ctn_layer);
        }
        var YY_dialog_bottom_layer = document.createElement("div");
        YY_dialog_bottom_layer.id = "YY_dialog_bottom_" + this.content_id;
        YY_dialog_bottom_layer.style.height = 5 + "px";
        YY_dialog_bottom_layer.style.overflow = "hidden";



        var YY_dialog_bottom_left_layer = document.createElement("div");

        YY_dialog_bottom_left_layer.id = "YY_dialog_bottom_left_" + this.content_id;
        YY_dialog_bottom_left_layer.style.width = 5 + "px";
        YY_dialog_bottom_left_layer.style.height = 5 + "px";
        YY_dialog_bottom_left_layer.style.background ='url("' + domain_source + '/images/default_dialog_bg.gif")';
        YY_dialog_bottom_left_layer.style.styleFloat = "left";
        YY_dialog_bottom_left_layer.style.cssFloat = "left";
        YY_dialog_bottom_left_layer.style.backgroundPosition = "-22px -6px";
        YY_dialog_bottom_left_layer.style.overflow = "hidden";

        var YY_dialog_bottom_center_layer = document.createElement("div");
        YY_dialog_bottom_center_layer.id = "YY_dialog_bottom_center_" + this.content_id;
        YY_dialog_bottom_center_layer.style.width = this.dialog_width - 10 + "px";
        YY_dialog_bottom_center_layer.style.height = 5 + "px";
        YY_dialog_bottom_center_layer.style.styleFloat = "left";
        YY_dialog_bottom_center_layer.style.cssFloat = "left";
        YY_dialog_bottom_center_layer.style.background = "#fff";
        YY_dialog_bottom_center_layer.style.overflow = "hidden";

        var YY_dialog_bottom_right_layer = document.createElement("div");

        YY_dialog_bottom_right_layer.id = "YY_dialog_bottom_right_" + this.content_id;
        YY_dialog_bottom_right_layer.style.width = 5 + "px";
        YY_dialog_bottom_right_layer.style.height = 5 + "px";
        YY_dialog_bottom_right_layer.style.background ='url("' + domain_source + '/images/default_dialog_bg.gif")';
        YY_dialog_bottom_right_layer.style.styleFloat = "left";
        YY_dialog_bottom_right_layer.style.cssFloat = "left";
        YY_dialog_bottom_right_layer.style.backgroundPosition = "-28px -6px";
        YY_dialog_bottom_right_layer.style.overflow = "hidden";


        YY_dialog_bottom_layer.appendChild(YY_dialog_bottom_left_layer);
        YY_dialog_bottom_layer.appendChild(YY_dialog_bottom_center_layer);
        YY_dialog_bottom_layer.appendChild(YY_dialog_bottom_right_layer);

        YY_dialog_layer.appendChild(YY_dialog_bottom_layer);
        document.body.appendChild(YY_dialog_layer);

        if (document.getElementById(this.content_id) != null) {
            document.getElementById(this.content_id).style.display = 'block';
            document.getElementById("YY_dialog_content_" + this.content_id).appendChild(document.getElementById(this.content_id));
        }

        var YY_dialog_bg_layer = document.createElement("div");

        YY_dialog_bg_layer.id = "YY_dialog_bg_" + this.content_id;
        YY_dialog_bg_layer.style.filter = "progid:DXImageTransform.Microsoft.Alpha(style=4,opacity=30)";
        YY_dialog_bg_layer.style.opacity = 0.3;
        YY_dialog_bg_layer.style.position = "absolute";
        YY_dialog_bg_layer.style.width = this.dialog_width + 20 + "px";
        YY_dialog_bg_layer.style.height = this.dialog_height + 20 + "px";
        YY_dialog_bg_layer.style.zIndex = 101;
        YY_dialog_bg_layer.style.display = 'none';
        YY_dialog_bg_layer.style.top = Math.floor((get_height() - this.dialog_height) / 2) - 10 < 0 ? 0 : Math.floor((get_height() - this.dialog_height) / 2) - 10 + 'px';
        YY_dialog_bg_layer.style.left = Math.floor((get_width() - this.dialog_width) / 2) - 10 < 0 ? 0 : Math.floor((get_width() - this.dialog_width) / 2) - 10 + 'px';

        var YY_dialog_bg_top_layer = document.createElement("div");
        YY_dialog_bg_top_layer.id = "YY_dialog_bg_top_" + this.content_id;
        YY_dialog_bg_top_layer.style.height = 10 + "px";
        YY_dialog_bg_top_layer.style.overflow = "hidden";

        var YY_dialog_bg_top_left_layer = document.createElement("div");

        YY_dialog_bg_top_left_layer.id = "YY_dialog_bg_top_left_" + this.content_id;
        YY_dialog_bg_top_left_layer.style.width = 10 + "px";
        YY_dialog_bg_top_left_layer.style.height = 10 + "px";
        YY_dialog_bg_top_left_layer.style.background ='url("' + domain_source + '/images/default_dialog_bg.gif")';
        YY_dialog_bg_top_left_layer.style.styleFloat = "left";
        YY_dialog_bg_top_left_layer.style.cssFloat = "left";
        YY_dialog_bg_top_left_layer.style.overflow = "hidden";

        var YY_dialog_bg_top_center_layer = document.createElement("div");
        YY_dialog_bg_top_center_layer.id = "YY_dialog_bg_top_center_" + this.content_id;
        YY_dialog_bg_top_center_layer.style.width = this.dialog_width + "px";
        YY_dialog_bg_top_center_layer.style.height = 10 + "px";
        YY_dialog_bg_top_center_layer.style.styleFloat = "left";
        YY_dialog_bg_top_center_layer.style.cssFloat = "left";
        YY_dialog_bg_top_center_layer.style.background = "#000";
        YY_dialog_bg_top_center_layer.style.overflow = "hidden";

        var YY_dialog_bg_top_right_layer = document.createElement("div");

        YY_dialog_bg_top_right_layer.id = "YY_dialog_bg_top_right_" + this.content_id;
        YY_dialog_bg_top_right_layer.style.width = 10 + "px";
        YY_dialog_bg_top_right_layer.style.height = 10 + "px";
        YY_dialog_bg_top_right_layer.style.background ='url("' + domain_source + '/images/default_dialog_bg.gif")';
        YY_dialog_bg_top_right_layer.style.styleFloat = "left";
        YY_dialog_bg_top_right_layer.style.cssFloat = "left";
        YY_dialog_bg_top_right_layer.style.backgroundPosition = "-11px 0";
        YY_dialog_bg_top_right_layer.style.overflow = "hidden";

        YY_dialog_bg_top_layer.appendChild(YY_dialog_bg_top_left_layer);
        YY_dialog_bg_top_layer.appendChild(YY_dialog_bg_top_center_layer);
        YY_dialog_bg_top_layer.appendChild(YY_dialog_bg_top_right_layer);

        YY_dialog_bg_layer.appendChild(YY_dialog_bg_top_layer);

        var YY_dialog_bg_middle_layer = document.createElement("div");
        YY_dialog_bg_middle_layer.id = "YY_dialog_bg_middle_" + this.content_id;
        YY_dialog_bg_middle_layer.style.height = this.dialog_height + "px";
        YY_dialog_bg_middle_layer.style.width = this.dialog_width + 20 + "px";
        YY_dialog_bg_middle_layer.style.background = "#000";

        YY_dialog_bg_layer.appendChild(YY_dialog_bg_middle_layer);


        var YY_dialog_bg_bottom_layer = document.createElement("div");
        YY_dialog_bg_bottom_layer.id = "YY_dialog_bg_bottom_" + this.content_id;
        YY_dialog_bg_bottom_layer.style.height = 10 + "px";
        YY_dialog_bg_bottom_layer.style.overflow = "hidden";

        var YY_dialog_bg_bottom_left_layer = document.createElement("div");

        YY_dialog_bg_bottom_left_layer.id = "YY_dialog_bg_bottom_left_" + this.content_id;
        YY_dialog_bg_bottom_left_layer.style.width = 10 + "px";
        YY_dialog_bg_bottom_left_layer.style.height = 10 + "px";
        YY_dialog_bg_bottom_left_layer.style.background ='url("' + domain_source + '/images/default_dialog_bg.gif")';
        YY_dialog_bg_bottom_left_layer.style.styleFloat = "left";
        YY_dialog_bg_bottom_left_layer.style.cssFloat = "left";
        YY_dialog_bg_bottom_left_layer.style.backgroundPosition = "0 -11px";
        YY_dialog_bg_bottom_left_layer.style.overflow = "hidden";

        var YY_dialog_bg_bottom_center_layer = document.createElement("div");
        YY_dialog_bg_bottom_center_layer.id = "YY_dialog_bg_bottom_center_" + this.content_id;
        YY_dialog_bg_bottom_center_layer.style.width = this.dialog_width + "px";
        YY_dialog_bg_bottom_center_layer.style.height = 10 + "px";
        YY_dialog_bg_bottom_center_layer.style.styleFloat = "left";
        YY_dialog_bg_bottom_center_layer.style.cssFloat = "left";
        YY_dialog_bg_bottom_center_layer.style.background = "#000";
        YY_dialog_bg_bottom_center_layer.style.overflow = "hidden";

        var YY_dialog_bg_bottom_right_layer = document.createElement("div");

        YY_dialog_bg_bottom_right_layer.id = "YY_dialog_bg_bottom_right_" + this.content_id;
        YY_dialog_bg_bottom_right_layer.style.width = 10 + "px";
        YY_dialog_bg_bottom_right_layer.style.height = 10 + "px";
        YY_dialog_bg_bottom_right_layer.style.background ='url("' + domain_source + '/images/default_dialog_bg.gif")';
        YY_dialog_bg_bottom_right_layer.style.styleFloat = "left";
        YY_dialog_bg_bottom_right_layer.style.cssFloat = "left";
        YY_dialog_bg_bottom_right_layer.style.backgroundPosition = "-11px -11px";
        YY_dialog_bg_bottom_right_layer.style.overflow = "hidden";

        YY_dialog_bg_bottom_layer.appendChild(YY_dialog_bg_bottom_left_layer);
        YY_dialog_bg_bottom_layer.appendChild(YY_dialog_bg_bottom_center_layer);
        YY_dialog_bg_bottom_layer.appendChild(YY_dialog_bg_bottom_right_layer);

        YY_dialog_bg_layer.appendChild(YY_dialog_bg_bottom_layer);

        document.body.appendChild(YY_dialog_bg_layer);
    };

    this.set_button = function (id, state, val) {
        if (typeof id == 'undefined' || id == '') return false;
        if (typeof state == 'undefined') state = true;
        obj = document.getElementById("YY_dialog_button_center_" + this.content_id + '_' + id);
        if (typeof val != 'undefined' && val != '') obj.innerHTML = val;
        if (!state) {
            obj.setAttribute('disabled', 'disabled');

        } else {
            obj.removeAttribute('disabled', 'disabled');

        }
    };

    this.show_action = function (action_str, type, loading) {
        if (typeof type == 'undefined') type = 'show';
        if (typeof loading == 'undefined') loading = true;
        if (type == 'hide') return false;
        var YY_dialog_action_ctn_layer = document.getElementById("YY_dialog_action_ctn_" + this.content_id);
        if (document.getElementById("YY_dialog_action_reply_" + this.content_id) == null) {
            var YY_dialog_action_reply_layer = document.createElement("div");
            YY_dialog_action_reply_layer.id = "YY_dialog_action_reply_" + this.content_id;

            YY_dialog_action_reply_layer.style.color = "#999";
            YY_dialog_action_reply_layer.style.height = 33 + "px";
            YY_dialog_action_reply_layer.style.lineHeight = 33 + "px";
            YY_dialog_action_reply_layer.style.styleFloat = "left";
            YY_dialog_action_reply_layer.style.cssFloat = "left";
            YY_dialog_action_reply_layer.style.paddingLeft = "35px";
            if (loading)
                YY_dialog_action_reply_layer.style.background = 'url("' + domain_source + '/images/loading_s.gif") no-repeat scroll 15px center #FFFFFF';
            else
                YY_dialog_action_reply_layer.style.background = '#FFFFFF';
            if (typeof action_str != 'undefined' && action_str != '') {
                YY_dialog_action_reply_layer.innerHTML = action_str;
            }
            YY_dialog_action_ctn_layer.appendChild(YY_dialog_action_reply_layer);
        } else {
            var YY_dialog_action_reply_layer = document.getElementById("YY_dialog_action_reply_" + this.content_id);
            if (type == 'show') {
                YY_dialog_action_reply_layer.style.display = 'block';
                if (loading)
                    YY_dialog_action_reply_layer.style.background = 'url("' + domain_source + '/images/loading_s.gif") no-repeat scroll 15px center #FFFFFF';
                else
                    YY_dialog_action_reply_layer.style.background = '#FFFFFF';
                if (typeof action_str != 'undefined' && action_str != '') {
                    YY_dialog_action_reply_layer.innerHTML = action_str;
                }
            } else {
                YY_dialog_action_reply_layer.style.display = 'none';
            }
        }
    }

    this.create_ctn = function () {
        var YY_dialog_ctn = document.createElement("div");

        YY_dialog_ctn.id = "YY_dialog_ctn_" + this.content_id;
        YY_dialog_ctn.style.position = "absolute";

        YY_dialog_ctn.style.width = this.dialog_width + "px";
        YY_dialog_ctn.style.height = this.dialog_height + "px";
        YY_dialog_ctn.style.zIndex = 102;
        YY_dialog_ctn.style.display = 'none';
        if (this.pos_x != null) {
            YY_dialog_ctn.style.top = this.pos_y + 'px';
            YY_dialog_ctn.style.left = this.pos_x + 'px';
        } else {
            YY_dialog_ctn.style.top = Math.floor((get_height() - this.dialog_height) / 2) < 5 ? 5 : Math.floor((get_height() - this.dialog_height) / 2) + 'px';
            YY_dialog_ctn.style.left = Math.floor((get_width() - this.dialog_width) / 2) < 5 ? 5 : Math.floor((get_width() - this.dialog_width) / 2) + 'px';
        }
        if (this.force_center) YY_dialog_ctn.setAttribute('YY_dialog_position', 'center');
        if (document.getElementById(this.content_id) != null) {
            document.getElementById(this.content_id).style.display = 'block';
            YY_dialog_ctn.appendChild(document.getElementById(this.content_id));
        }
        document.body.appendChild(YY_dialog_ctn);
    }

    this.create_mask = function () {
        if (document.getElementById('YY_mask') == null) {
            var maskLayer = document.createElement("div");
            maskLayer.id = "YY_mask";
            maskLayer.setAttribute('YY_dialog_id', "YY_dialog_ctn_" + this.content_id);
            maskLayer.setAttribute('YY_dialog_content_id', this.content_id);
            maskLayer.style.position = "absolute";
            maskLayer.style.filter = "progid:DXImageTransform.Microsoft.Alpha(style=4,opacity=40)";
            maskLayer.style.opacity = 0.4;
            maskLayer.style.background = "#000000";
            maskLayer.style.top = "0px";
            maskLayer.style.left = "0px";
            maskLayer.style.width = get_width() + "px";
            maskLayer.style.height = get_height() + "px";
            maskLayer.style.zIndex = 100;
            maskLayer.style.display = 'none';
            document.body.appendChild(maskLayer);
        }
    }

    this.show_mask = function () {
        var YY_mask = document.getElementById("YY_mask");
        if (YY_mask == null) {

        } else {
            this.show('YY_mask');
        }
    };

    this.show_dialog = function () {
        if (this.restrict) this.show_mask();
        if (this.pos_x == null) this.center_dialog();
        this.show("YY_dialog_ctn_" + this.content_id);
        this.show("YY_dialog_bg_" + this.content_id);
        hide_select();
        if (this.focus_btn != '') document.getElementById(this.focus_btn).focus();
    };

    this.center_dialog = function () {
        var YY_dialog_ctn = document.getElementById("YY_dialog_ctn_" + this.content_id);
        var YY_dialog_bg = document.getElementById("YY_dialog_bg_" + this.content_id);
        var width = get_width();
        var height = get_height();
        YY_dialog_ctn.style.top = Math.floor(document.documentElement.scrollTop + document.body.scrollTop + (document.documentElement.clientHeight - this.dialog_height) / 2) < 10 ? 10 : Math.floor(document.documentElement.scrollTop + document.body.scrollTop + (document.documentElement.clientHeight - this.dialog_height) / 2) + 'px';
        YY_dialog_ctn.style.left = Math.floor(document.documentElement.scrollLeft + (document.documentElement.clientWidth - this.dialog_width) / 2) < 10 ? 10 : Math.floor(document.documentElement.scrollLeft + (document.documentElement.clientWidth - this.dialog_width) / 2) + 'px';
        if (this.package) {
            YY_dialog_bg.style.top = (Math.floor(document.documentElement.scrollTop + document.body.scrollTop + (document.documentElement.clientHeight - this.dialog_height) / 2) - 10) < 0 ? 0 : (Math.floor(document.documentElement.scrollTop + document.body.scrollTop + (document.documentElement.clientHeight - this.dialog_height) / 2) - 10) + 'px';
            YY_dialog_bg.style.left = (Math.floor(document.documentElement.scrollLeft + (document.documentElement.clientWidth - this.dialog_width) / 2) - 10) < 0 ? 0 : (Math.floor(document.documentElement.scrollLeft + (document.documentElement.clientWidth - this.dialog_width) / 2) - 10) + 'px';
        }
    };

    this.show = function (ele) {
        if (document.getElementById(ele) != null) document.getElementById(ele).style.display = 'block';
    };

    this.close_dialog = function () {
        if (typeof (this.close) == 'function') this.close();
        if (document.getElementById("YY_dialog_ctn_" + this.content_id) != null) document.getElementById("YY_dialog_ctn_" + this.content_id).style.display = 'none';
        if (document.getElementById("YY_dialog_bg_" + this.content_id) != null) document.getElementById("YY_dialog_bg_" + this.content_id).style.display = 'none';
        if (document.getElementById("YY_mask") != null) document.getElementById("YY_mask").style.display = 'none';
        hide_select(false);
    };

    hide_select = function (action) {
        var selects = document.getElementsByTagName("SELECT");
        for (var i = 0; i < selects.length; i++) {
            if (action == false && selects[i].className.indexOf('uboxstyle') < 0 && selects[i].className.indexOf('dialog_select') < 0) {
                selects[i].style.display = "inline";
            } else if (selects[i].className.indexOf('uboxstyle') < 0 && selects[i].className.indexOf('dialog_select') < 0) {
                selects[i].style.display = "none";
            }
        }
    };

    down = function (e) {

        var content_id = this.dialog_id;
        var YY_dialog_ctn = document.getElementById("YY_dialog_ctn_" + content_id);
        var YY_dialog_width = parseInt(YY_dialog_ctn.style.width.replace(/px/, ""));
        var YY_dialog_height = parseInt(YY_dialog_ctn.style.height.replace(/px/, ""));
        var event = window.event || e;
        if (YY_dialog_ctn.style.top == '') YY_dialog_ctn.style.top = 0;
        if (YY_dialog_ctn.style.left == '') YY_dialog_ctn.style.left = 0;
        tHeight = event.clientY
				- parseInt(YY_dialog_ctn.style.top.replace(/px/, ""));
        lWidth = event.clientX
				- parseInt(YY_dialog_ctn.style.left.replace(/px/, ""));
        document.onmousemove = function (e) {
            var YY_mask = document.getElementById("YY_mask");
            var all_width = get_width();
            var all_height = get_height();

            if (null != YY_mask) {
                YY_mask.style.width = all_width + "px";
                YY_mask.style.height = all_height + "px";
            }

            var YY_dialog_ctn = document.getElementById("YY_dialog_ctn_" + content_id);
            var YY_dialog_bg = document.getElementById("YY_dialog_bg_" + content_id);
            var event = window.event || e;
            var top = event.clientY - tHeight;
            var left = event.clientX - lWidth;

            top = top > all_height - YY_dialog_height - 10 ? all_height - YY_dialog_height - 10 : top;
            top = top < 10 ? 10 : top;
            left = left > all_width - YY_dialog_width - 10 ? all_width - YY_dialog_width - 10 : left;
            left = left < 10 ? 10 : left;
            YY_dialog_ctn.style.top = top + "px";
            YY_dialog_ctn.style.left = left + "px";
            if (YY_dialog_bg != null) {
                YY_dialog_bg.style.top = top - 10 + "px";
                YY_dialog_bg.style.left = left - 10 + "px";
            }

        };
        YY_dialog_ctn.style.filter = "progid:DXImageTransform.Microsoft.Alpha(style=4,opacity=70)";
        YY_dialog_ctn.style.opacity = 0.7;
        document.onmouseup = function () {
            document.onmousemove = null;
            YY_dialog_ctn.style.filter = "";
            YY_dialog_ctn.style.opacity = 1;
        };
    };

    re_mask = function (e) {
        var YY_mask = document.getElementById("YY_mask");

        YY_mask.style.width = get_width() + "px";
        YY_mask.style.height = get_height() + "px";
        if (YY_mask.getAttribute('YY_dialog_content_id') != null) {
            var YY_dialog_content_id = YY_mask.getAttribute('YY_dialog_content_id');
            var YY_dialog_ctn = document.getElementById("YY_dialog_ctn_" + YY_dialog_content_id);
            var YY_dialog_bg = document.getElementById("YY_dialog_bg_" + YY_dialog_content_id);
            var width = get_width();
            var height = get_height();
            if (YY_dialog_ctn != null && YY_dialog_ctn.getAttribute('YY_dialog_position') == 'center') {
                var YY_dialog_width = parseInt(YY_dialog_ctn.style.width.replace(/px/, ""));
                var YY_dialog_height = parseInt(YY_dialog_ctn.style.height.replace(/px/, ""));
                YY_dialog_ctn.style.top = Math.floor(document.documentElement.scrollTop + (document.documentElement.clientHeight - YY_dialog_height) / 2) < 10 ? 10 : Math.floor(document.documentElement.scrollTop + (document.documentElement.clientHeight - YY_dialog_height) / 2) + 'px';
                YY_dialog_ctn.style.left = Math.floor(document.documentElement.scrollLeft + (document.documentElement.clientWidth - YY_dialog_width) / 2) < 10 ? 10 : Math.floor(document.documentElement.scrollLeft + (document.documentElement.clientWidth - YY_dialog_width) / 2) + 'px';
                if (YY_dialog_bg != null) {
                    YY_dialog_bg.style.top = (Math.floor(document.documentElement.scrollTop + (document.documentElement.clientHeight - YY_dialog_height) / 2) - 10) < 0 ? 0 : (Math.floor(document.documentElement.scrollTop + (document.documentElement.clientHeight - YY_dialog_height) / 2) - 10) + 'px';
                    YY_dialog_bg.style.left = (Math.floor(document.documentElement.scrollLeft + (document.documentElement.clientWidth - YY_dialog_width) / 2) - 10) < 0 ? 0 : (Math.floor(document.documentElement.scrollLeft + (document.documentElement.clientWidth - YY_dialog_width) / 2) - 10) + 'px';
                }
            }
        }
    };

    if (typeof (params) == "object") this.config(params);
    if (this.package)
        this.create_dialog();
    else
        this.create_ctn();
    if (this.dragger != null) {
        dragger_obj = document.getElementById(this.dragger);
        dragger_obj.onmousedown = down;
        dragger_obj.dialog_id = this.content_id;
        dragger_obj.onselectstart = new Function("return false");
    }
    if (this.restrict) {
        this.create_mask();
        window.onresize = re_mask;
        window.onscroll = re_mask;
    }
    if (this.focus_btn != '') {
        var focus_btn = this.focus_btn;

        document.onkeydown = function (evt) {
            var evt = window.event ? window.event : evt;
            if (evt.keyCode == 13) {

                if (document.all) {
                    document.getElementById(focus_btn).click();
                }
                else {
                    {
                        var evt = document.createEvent("MouseEvents");
                        evt.initEvent("click", true, true);
                        document.getElementById(focus_btn).dispatchEvent(evt);
                    }
                }

            }
        };
    }
}














var commonappDialog, commonbindDialog;
if (document.domain.indexOf('gaitu.com') >= 0) {
    //document.domain = 'gaitu.com';
    var serviceurl = "http://service.gaitu.com";
    var localbackurl = "http://p.gaitu.com";
} else if (document.domain.indexOf('gaitu.cn') >= 0) {
    document.domain = 'gaitu.cn';
    var serviceurl = "http://service.gaitu.cn";
    var localbackurl = "http://p.gaitu.com";
} else if (document.domain.indexOf('gaitu.eric') >= 0) {
    //document.domain = 'gaitu.eric';
    var serviceurl = "http://service.gaitu.cn";
    var localbackurl = "http://p.gaitu.com";
}
else {
    document.domain = '61.136.198.221';
    var serviceurl = "http://service.gaitu.cn";
    var localbackurl = "http://p.gaitu.com";
}
function openQQ() {
    var A = window.open("http://applogin.gaitu.com/app/qq/LoginToQQ.aspx", "TencentLogin", "width=510,height=400,menubar=0,scrollbars=0, status=1,titlebar=0,toolbar=0,location=1");
}
function openAliPay() {
    var A = window.open(serviceurl + "/app/alipay/Logintoali.aspx", "TencentLogin", "width=960,height=600,menubar=0,scrollbars=0, titlebar=0,toolbar=0,location=1");
}

function openWeiBo() {
    var A = window.open(serviceurl + "/app/weibo/logintoweibo.aspx", "TencentLogin", "width=640,height=450,menubar=0,scrollbars=0, status=1,titlebar=0,toolbar=0,location=1");
}
function closeappLogin(bindstat, logid) {
    expressLoginDialog.close_dialog();
    //登陆失败
    if (bindstat == 0) {
        express_login();
    }
    //第一次绑定
    else if (bindstat == 1) {
        show_appbind_dialog('', logid);
    }
    //登陆成功
    else if (bindstat == 2) {
        getLogedJson();
    }
}
function show_appbind_dialog(callback, otherparam) {
    if (document.getElementById('commonbindDialog') == null) {
        var d = document.createElement("div"); // 创建对象，下面就是设置属性了
        d.id = "commonbindDialog";
        d.title = "绑定账号";
        document.body.appendChild(d);
    }
    var url = "http://applogin.gaitu.com/app/bind.aspx";
    if (typeof callback != 'undefined') {
        url += '?callback=' + callback + '&callurl=' + otherparam;
    }
    document.getElementById('commonbindDialog').innerHTML = '<iframe src="' + url + '" width="510" height="400" scrolling="no" allowtransparency="true" frameborder="0" id="select_img_frm" name="select_img_frm"></iframe>';
    var p = {
        content_id: "commonbindDialog",
        title: '绑定账号',
        width: 530,
        height: 450
    };
    //if (typeof(sysInfoDialog)=="undefined")var sysInfoDialog;
    commonbindDialog = new YY_dialog(p);
    commonbindDialog.show_dialog();
}
function getLogedJson() {
    if (typeof expressLoginDialog == 'undefined') {
        location.href = localbackurl;
    }
    if (commonbindDialog != null) {
        commonbindDialog.close_dialog();
    }
    var post_data = "dotype=3";
    $.ajax({
        url: '/ajaxpage/logon.aspx',
        type: 'POST',
        data: post_data,
        dataType: 'html',
        timeout: 60000,
        error: function (html) {
            //alert('读取失败，请稍后重试！');
        },
        success: function (html) {
            if (html.split("￥￥￥")[0] == 1) {
                $("#newHeadHtml").html(html.split("￥￥￥")[1]);
            } else if (html == 0 || html == -3) {
                express_login();
            }
        }
    });
}